<?php

declare(strict_types=1);

use App\Migration\MigrationInterface;
use PDO;

return new class implements MigrationInterface {
    public function getId(): string
    {
        return '20250121000200_seed_posts';
    }

    public function up(PDO $pdo): void
    {
        $statement = $pdo->prepare('INSERT INTO posts (title, body) VALUES (:title, :body)');

        foreach ($this->seedPosts() as $post) {
            $statement->execute($post);
        }
    }

    public function down(PDO $pdo): void
    {
        $pdo->exec('TRUNCATE TABLE posts RESTART IDENTITY');
    }

    /**
     * @return list<array{title:string,body:string}>
     */
    private function seedPosts(): array
    {
        return [
            ['title' => 'Hello from SQLite', 'body' => 'A starter post loaded from the database seed.'],
            ['title' => 'Second Entry', 'body' => 'This record shows how to extend the seed set.'],
        ];
    }
};
